Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

The webapp crashes when the backend introduces new protobuf fields because fromJson strictly validates against the schema.

Changes

  • Created protobuf-utils.ts: Wraps fromJson with ignoreUnknownFields: true option
  • Updated 12 files: Changed all fromJson imports to use the new wrapper
// Before: crashes on unknown fields
import { fromJson } from "@bufbuild/protobuf";
const message = fromJson(MessageSchema, jsonData);

// After: ignores unknown fields
import { fromJson } from "./libs/protobuf-utils";
const message = fromJson(MessageSchema, jsonData);

This allows older webapp versions to work with newer backend versions that add fields, following standard protobuf forward compatibility patterns.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • buf.build
    • Triggering command: /usr/local/bin/node node /usr/local/bin/npm install (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

current webapp verifies all grpc schema fields, but when a new field is introduced, the front end will crash completely. please make a PR to let the webapp able to accept json schemas with new fields.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Note

Ensures protobuf JSON parsing ignores unknown fields to avoid crashes when backend adds new fields.

  • Adds libs/protobuf-utils.ts with fromJson wrapper (ignoreUnknownFields: true)
  • Refactors usages across components, hooks, stores, and query layer to import fromJson from the new utility instead of @bufbuild/protobuf
  • Adds libs/protobuf-utils.test.ts documenting manual tests for forward compatibility
  • Cleans up related imports (e.g., removing unused fromJson from @bufbuild/protobuf)

Written by Cursor Bugbot for commit a3862a6. This will update automatically on new commits. Configure here.

Copilot AI changed the title [WIP] Update webapp to handle new JSON schema fields without crashing Add ignoreUnknownFields to protobuf JSON parsing Dec 19, 2025
Copilot AI requested a review from Junyi-99 December 19, 2025 02:14
@Junyi-99 Junyi-99 marked this pull request as ready for review January 7, 2026 15:01
Copilot AI review requested due to automatic review settings January 7, 2026 15:01
@Junyi-99 Junyi-99 moved this from Icebox to In review in Project PaperDebugger Jan 7, 2026
@Junyi-99 Junyi-99 changed the title Add ignoreUnknownFields to protobuf JSON parsing feat: add ignoreUnknownFields to protobuf JSON parsing Jan 7, 2026
@Junyi-99 Junyi-99 merged commit 3942b9e into main Jan 7, 2026
6 of 12 checks passed
@Junyi-99 Junyi-99 deleted the copilot/update-webapp-json-schema-handling branch January 7, 2026 15:03
@github-project-automation github-project-automation bot moved this from In review to Done in Project PaperDebugger Jan 7, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a critical issue where the webapp crashes when the backend introduces new protobuf fields. By wrapping all fromJson calls with a utility that sets ignoreUnknownFields: true, the webapp can now gracefully handle responses from newer backend versions, implementing proper forward compatibility.

Key Changes:

  • Created a protobuf-utils.ts wrapper that configures fromJson to ignore unknown fields
  • Updated all 12 files that use fromJson to import from the new wrapper instead of directly from @bufbuild/protobuf
  • Added a test/documentation file demonstrating the expected behavior

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
webapp/_webapp/src/libs/protobuf-utils.ts New utility wrapper that adds ignoreUnknownFields: true to all protobuf JSON parsing
webapp/_webapp/src/libs/protobuf-utils.test.ts Documentation/manual test file demonstrating the wrapper's behavior with unknown fields
webapp/_webapp/src/views/prompts/prompt-library-table.tsx Updated fromJson import to use the new wrapper
webapp/_webapp/src/views/devtools/index.tsx Updated fromJson import to use the new wrapper
webapp/_webapp/src/stores/conversation/handlers/handleStreamError.ts Updated fromJson import to use the new wrapper
webapp/_webapp/src/stores/conversation/handlers/converter.ts Updated fromJson import to use the new wrapper
webapp/_webapp/src/stores/conversation/conversation-store.ts Updated fromJson import to use the new wrapper
webapp/_webapp/src/query/utils.ts Updated fromJson import to use the new wrapper
webapp/_webapp/src/query/api.ts Updated fromJson import to use the new wrapper
webapp/_webapp/src/libs/apiclient.ts Updated fromJson import to use the new wrapper
webapp/_webapp/src/hooks/useSendMessageStream.ts Updated fromJson import to use the new wrapper
webapp/_webapp/src/components/message-entry-container/tools/paper-score.tsx Updated fromJson import to use the new wrapper
webapp/_webapp/src/components/message-entry-container/tools/paper-score-comment/index.tsx Updated fromJson import to use the new wrapper
webapp/_webapp/src/components/message-entry-container/tools/paper-score-comment/add-comments-button.tsx Updated fromJson import to use the new wrapper

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +10 to +16
export function fromJson<Desc extends DescMessage>(
schema: Desc,
json: JsonValue,
): InstanceType<Desc["message"]> {
return bufFromJson(schema, json, {
ignoreUnknownFields: true,
});
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wrapper function doesn't support passing additional options that might be needed in the future. Consider adding an optional third parameter to allow callers to override or extend the default options while still preserving the ignoreUnknownFields: true default behavior. This would make the wrapper more flexible for future use cases where other JsonReadOptions might be needed (e.g., typeRegistry for custom types).

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +74
/**
* Test file to demonstrate that the protobuf-utils wrapper handles unknown fields gracefully.
*
* This test can be run manually to verify the fix. Since the project doesn't have
* a test runner configured, this serves as documentation of the expected behavior.
*
* To test manually:
* 1. Add a new field to a protobuf schema on the backend
* 2. Deploy the backend
* 3. Use an older version of the webapp (without regenerating protobuf files)
* 4. Verify that the webapp doesn't crash when receiving the new field
*/

import { fromJson } from "./protobuf-utils";
import { MessageSchema } from "../pkg/gen/apiclient/chat/v2/chat_pb";

/**
* Example: Testing that fromJson ignores unknown fields
*
* This would simulate a backend returning a message with a new field
* that doesn't exist in the current schema.
*/
function testIgnoreUnknownFields() {
// Simulate JSON response from backend with an extra field "newField"
const jsonWithUnknownField = {
messageId: "test-123",
payload: {
user: {
content: "Hello",
selectedText: "",
newFieldThatDoesntExistYet: "This is a new field from a newer backend version",
},
},
timestamp: "0",
};

try {
// This should NOT throw an error even though "newFieldThatDoesntExistYet" doesn't exist in the schema
const message = fromJson(MessageSchema, jsonWithUnknownField);
console.log("✓ Successfully parsed message with unknown field");
console.log(" Message ID:", message.messageId);
console.log(" User content:", message.payload.user?.content);
return true;
} catch (error) {
console.error("✗ Failed to parse message with unknown field:", error);
return false;
}
}

/**
* Example: Testing that fromJson still validates required fields
*/
function testRequiredFieldsStillValidated() {
// Missing required messageId field
const invalidJson = {
payload: {
user: {
content: "Hello",
},
},
};

try {
const message = fromJson(MessageSchema, invalidJson);
console.log("✓ Parsed message (messageId will be empty string):", message.messageId);
return true;
} catch (error) {
console.error("✗ Failed to parse message:", error);
return false;
}
}

// Export test functions for manual testing
export { testIgnoreUnknownFields, testRequiredFieldsStillValidated };
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test file contains only exported functions but no executable tests. Since the project doesn't have a test runner configured (no test scripts in package.json, no jest/vitest/mocha dependencies), this file serves as documentation rather than automated tests. Consider either: 1) setting up a test runner and converting these to actual test cases, or 2) renaming the file to something like protobuf-utils.examples.ts or moving the documentation to a comment/doc file to better reflect its current purpose as manual testing documentation.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants